import java.sql.*;
public class JDBCExample2 {
	public static void main(String[] args) throws ClassNotFoundException,
		SQLException {
		String username = "root";
		String password = "password";
		String tablename = "PROJECT";
		String fieldname = "PKEY";
		String fieldname2 = "PNAME";
		
		String query = "SELECT " + fieldname + " FROM " + tablename + ";";
		String query1 = "SELECT * FROM PROJECT;";
		String query2 = "select jiraissue.pkey, issuetype.pname from jiraissue, issuetype where jiraissue.issuetype=issuetype.id;";
		String query3 = "SELECT priority.pname FROM jiraissue INNER JOIN priority ON jiraissue.priority = priority.id;";

		String url = "jdbc:mysql://localhost/JIRADB";
		
		Class.forName("com.mysql.jdbc.Driver"); 
		
		Connection con = DriverManager.getConnection(url, username, password);
		
		System.out.println ("Database connection established");
		Statement stmt = con.createStatement();
		ResultSet rs = stmt.executeQuery(query);
		System.out.println("The contents of field " + fieldname + ":");
		while (rs.next())
			System.out.print(rs.getString(1) + ", ");
		// note that getString anomalously starts counting at 1, not 0
		System.out.println();
		rs.close();
		ResultSet rs1 = stmt.executeQuery(query1);
		System.out.println("The contents of table " + tablename + ":");
		while (rs1.next())
			System.out.print(rs1.getString(1) + ", ");
		System.out.println();
		rs1.close();
		rs1.close();
		
		ResultSet rs2 = stmt.executeQuery(query2);
		System.out.println("The contents of field " + fieldname + ":");
		while (rs2.next())
			System.out.print(rs2.getString(1) + ", ");
		// note that getString anomalously starts counting at 1, not 0
		System.out.println();
		rs2.close();
		
		ResultSet rs3 = stmt.executeQuery(query2);
		System.out.println("The contents of field " + fieldname2 + ":");
		while (rs3.next())
			System.out.print(rs3.getString(2) + ", ");
		// note that getString anomalously starts counting at 1, not 0
		System.out.println();
		rs3.close();
		
		ResultSet rs4 = stmt.executeQuery(query3);
		System.out.println("The contents of field " + fieldname2 + ":");
		while (rs4.next())
			System.out.print(rs4.getString(1) + ", ");
		// note that getString anomalously starts counting at 1, not 0
		System.out.println();
		rs4.close();
		
		stmt.close();
		con.close();
		System.out.println ("Database connection terminated");
	}
}